package gms.simulation;

import gms.topology.Topology;

import java.io.Writer;

/**
 * Created by IntelliJ IDEA.
 * User: Anton Dunaev
 * Date: 07.09.2007
 * Time: 16:49:05
 */
public class Do extends Operation
{
    gms.cwf.Do op;
    NodeSimulation node_sim = null;
    boolean is_add_to_time_line = false;

    public Do( gms.cwf.Do op)
    {
        this.op = op;
        node_sim = NodeSimulation.getInstance();
    }

    public long getNode_id()
    {
        return op.getNode_id();
    }

    public double getAmount()
    {
        return op.getAmount();
    }

    public boolean tryStep()
            throws Exception
    {
        if( !is_add_to_time_line )
        {
            node_sim.addAction( this );
            is_add_to_time_line = true;
            return true;
        }else if( !isApproved() & node_sim.isApproved( this ) )
        {
            setTime_end( node_sim.getTime_end(this) );
            setApproved();
            return true;
        }else
            return false;
    }

    public double getShort_path_time_end()
    {
        return getTime_end();
    }

    protected void setTime_end(double time_end)
    {
        super.setTime_end( time_end );
        setShort_path_time_end( time_end );
    }

    public void printStatus(Writer w, String prefix)
    {
        try
        {
            w.write( prefix + "Do\t" + getId() + "\tStart:" + getTime_start() + "\tEnd:" + getTime_end() + "\t" + isApproved() + "\tAmount:" + getAmount() + "\n");
        }catch( Exception ex )
        {
            System.out.println(ex.getMessage());
        }
    }
    
}
